<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 匹配随意打乱 'aabbcc' true-->
    <script src="">
        /**
* @param {string} s
* @return {boolean}
随意打乱项
*/

        let isValid = function (s) {
            let newarr = []
            for (let i = 0; i < s.length; i++) {
                if (s[i] == 'a' || s[i] == 'b') newarr.push(s[i])
                if (s[i] == 'c') {
                    let num = false
                    for (let j = 0; j < newarr.length; j++) {
                        if (newarr[j] == 'a') {
                            num = true
                            let numis = false
                            for (let k = j + 1; k < newarr.length; k++) {
                                if (newarr[k] == 'b') {
                                    newarr.splice(k, 1)
                                    numis = true
                                    break
                                }
                            }
                            if (numis) {
                                newarr.splice(j, 1)
                                break
                            } {
                                return false
                            }
                        }
                    }
                    if (!num) return false
                }
            }
            return newarr.length == 0
        };
    </script>

    <!-- 栈 c前必定ba 'aabbcc' false-->
    <script>
        // var isValid = function (s) {
        //     let newarr = []
        //     for (let i = 0; i < s.length; i++) {
        //         if (s[i] == 'a' || s[i] == 'b') newarr.push(s[i])
        //         if (s[i] == 'c') {
        //             if (newarr[newarr.length - 1] != 'b' || newarr[newarr.length - 2] != 'a') return false
        //             newarr.splice(-2)
        //         }
        //     }
        //     return !(newarr.length)
        // };
    </script>
</body>

</html>